package com.nineclock.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.nineclock.auth.mapper.SysUserMapper;
import com.nineclock.auth.service.SysUserService;
import com.nineclock.common.utils.BeanHelper;
import com.nineclock.system.dto.SysUserDTO;
import com.nineclock.system.pojo.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    SysUserMapper sysUserMapper;

    @Override
    public SysUserDTO queryUser(String username) {
        LambdaQueryWrapper<SysUser> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(SysUser::getStatus,1);
        queryWrapper.eq(SysUser::getUsername,username).or().eq(SysUser::getMobile,username);
        SysUser sysUser = sysUserMapper.selectOne(queryWrapper);

        if (sysUser!=null){
            return BeanHelper.copyProperties(sysUser,SysUserDTO.class);
        }
        return null;
    }
}
